package weaver.interfaces.jjy.duss.action;
import weaver.conn.RecordSet;
import weaver.general.BaseBean;
import weaver.general.Util;
import weaver.interfaces.jjy.duss.hr.HR016;
import weaver.interfaces.workflow.action.Action;
import weaver.soa.workflow.request.RequestInfo;

import java.util.HashMap;
import java.util.Map;
/**
 * @program: ecology-9-demo
 * @description: 促销员离职推送SAP
 * @author: Dusongsong
 * @create: 2019-12-10
 */
public class WeaHRcxylztsAction extends BaseBean implements Action{
    @Override
    public String execute(RequestInfo requestInfo) {
        RecordSet rs = new RecordSet();
        BaseBean baseBean = new BaseBean();
        String requestid = requestInfo.getRequestid();
        baseBean.writeLog("请求ID" + requestid);
        baseBean.writeLog("调用WeaHRcxylztsAction");
        String tablename = requestInfo.getRequestManager().getBillTableName();//主表
        rs.executeQuery("select ygh,lzrq,sjlxvalue,lzyyvalue,gysmcvalue from " + tablename + " where requestid=?", requestid);
        baseBean.writeLog("select ygh,lzrq,sjlxvalue,lzyyvalue,gysmcvalue from " + tablename + " where requestid=?" + requestid);
        rs.next();
        String PERNR = Util.null2String(rs.getString("ygh"));
        String BEGDA = Util.null2String(rs.getString("lzrq").replaceAll("-", ""));//离职日期
        String MASSN = Util.null2String(rs.getString("sjlxvalue"));//事件类型
        String MASSG = Util.null2String(rs.getString("lzyyvalue"));//事件原因
        String ZHR_SSGYS = Util.null2String(rs.getString("gysmcvalue"));//供应商编码

        Map<String, String> map = new HashMap();
        map.put("IV_PERNR", PERNR);
        map.put("PERNR",PERNR);
        map.put("BEGDA",BEGDA);
        map.put("MASSN",MASSN);
        map.put("MASSG",MASSG);
        map.put("ZHR_SSGYS",ZHR_SSGYS);

        HR016 hr016 = new HR016();
        try{
            Map resultMap = hr016.execute(map);
            String flag = (String)resultMap.get("flag");
            String message = (String)resultMap.get("message");
            baseBean.writeLog("SAP返回结果——flag:" + flag + ";message:" + message);
            if("s".equalsIgnoreCase(flag)){

                return Action.SUCCESS;
            }else {

                requestInfo.getRequestManager().setMessageid("111111");
                requestInfo.getRequestManager().setMessagecontent(message);
                return Action.FAILURE_AND_CONTINUE;
            }
        }catch(Exception e){
            e.printStackTrace();
            baseBean.writeLog("异常参考:" + e);
            requestInfo.getRequestManager().setMessageid("111111");
            requestInfo.getRequestManager().setMessagecontent(e.getMessage());
            return Action.FAILURE_AND_CONTINUE;
        }

    }
}
